<template>
  <div class="salarys">
    <el-card>
      <h3>测试上传组件</h3>
      <imageupload :imgUrl.sync="imgUrl"></imageupload>
    </el-card>
    <el-card>
      <h3>qrcode 的使用：地址转二维码</h3>
      <img style="width: 100px; height: 100px" :src="imgUrl" alt="" />
      <el-button @click="turnCode">点我将图片地址转为二维码</el-button>
      <h3>在这里面显示二维码</h3>
      <div>
        <canvas ref="myCanvas" />
      </div>
    </el-card>
  </div>
</template>

<script>
import QrCode from 'qrcode'
export default {
  data () {
    return {
      imgUrl:
        'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202005%2F20%2F20200520024521_zkkfs.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628406412&t=7a39280983bb0fbac6affffb4a5185e9'
      // imgUrl: ''
    }
  },
  methods: {
    // 将图片地址转为二维码
    turnCode () {
      // QrCode.toCanvas(dom(需要显示二维码的dom), info(要生成二维码的地址),{配制(width,height)})
      QrCode.toCanvas(this.$refs.myCanvas, this.imgUrl, {
        width: 200, // 生成二维码的宽度
        height: 200 // 生成二维码的高度
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.salarys {
  padding: 20px;
}
</style>
